home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / fract / FlashMandel.lha / FlashMandel / Sources / Modules / MandReal.P < prev    next >
Text File  |  1999-01-22  |  4KB  |  88 lines

  1. ************************************************************************
  2. **            Written by Dino Papararo            09-Nov-1998
  3. **
  4. **  FUNCTION
  5. **
  6. **    MandReal -- perform Z = Z^2 + C iteration.
  7. **
  8. **  SYNOPSIS
  9. **
  10. **    WORD MandFPU (WORD Iterations,long double Cre,long double Cim)
  11. **
  12. **
  13. **  DESCRIPTION
  14. **
  15. **  C equivalent function:
  16. **
  17. **    ***************************************************************
  18. **    *WORD Real (WORD Iterazioni,long double Cre,long double Cim)***
  19. **    *{                                                          ***
  20. **    *register long double zr,zi,zi2,Dist,MaxDist;               ***
  21. **    *                                                           ***
  22. **    *  zi = Cim;                                                ***
  23. **    *                                                           ***
  24. **    *  zr = Cre;                                                ***
  25. **    *                                                           ***
  26. **    *  MaxDist = 4.0;                                           ***
  27. **    *                                                           ***
  28. **    *  do {                                                     ***
  29. **    *       zi2 = zi * zi;                                      ***
  30. **    *                                                           ***
  31. **    *       zi = zr + zr;                                       ***
  32. **    *                                                           ***
  33. **    *       Dist = zr * zr + zi2;                               ***
  34. **    *                                                           ***
  35. **    *       zr = zr * zr - zi2;                                 ***
  36. **    *                                                           ***
  37. **    *       zi = zi * zi + Cim;                                 ***
  38. **    *                                                           ***
  39. **    *       zr = zr + Cre;                                      ***
  40. **    *                                                           ***
  41. **    *     } while (-- Iterazioni && (MaxDist > Dist));          ***
  42. **    *                                                           ***
  43. **    *  if (Iterazioni <= 0) Iterazioni = 1;                     ***
  44. **    *                                                           ***
  45. **    *  return Iterazioni;                                       ***
  46. **    *}                                                          ***
  47. **    ***************************************************************
  48. **
  49. **  This function tests if a point belongs or not at mandelbrot's set
  50. **
  51. **  Optimized for pipelines of PPC coprocessors
  52. **
  53. **  NOTICE: ALL VARIABLES ARE INTO REGISTERS FOR FULL SPEEEED
  54. **
  55. **  r3:Iterations
  56. **  f0:Cre f1:Cim f2:Zr f3:Zi f4:Zi2 f5:Dist f6:MaxDist
  57.  
  58.         XDEF _MandPPC
  59.  
  60. _MandPPC:
  61.  
  62.         prolog            ; start
  63.  
  64.         fmr   f3,f1       ; zi   = cim
  65.         fmr   f2,f0       ; zr   = cre
  66.         ls    f7,Four     ; maxdist = 4.0
  67.         mtctr r3          ; load reg counter with iterations
  68.  
  69. .Loop
  70.         fmul  f4,f3,f3    ; zi2 = zi * zi
  71.         fadd  f3,f2,f2    ; zi = 2 * zr
  72.         fmadd f5,f2,f2,f4 ; dist = zr * zr + zi2
  73.         fmsub f2,f2,f2,f4 ; zr [new] = zr * zr - zi2
  74.         fmadd f3,f3,f3,f1 ; zi = zi * zi + Cim
  75.         fadd  f2,f2,f0    ; zr [new] = zr + Cre
  76.         fcmpu f5,f6       ; if maxdist > dist  and
  77.         bdnzf GT,.Loop    ; if iterations != 0 loop
  78.  
  79. .Exit
  80.  
  81.         mfctr r3          ; store iterations from reg counter
  82.         ble   .Jump       ; if iterations <= 0
  83.         li    r3,1        ; Iterations = 1
  84. .Jump
  85.         epilog            ; end
  86.  
  87. Four:   dc.s 4.0
  88.